package com.cicigodd.brick.plug.pay.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author cicigodd
 * @date 2022-11-16 9:11
 */
@Configuration
public class WeixinPayConfig {


    @Resource
    private WeixinPayProperties weixinPayProperties;


    @Bean
    public WxPayService wxPayService() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(weixinPayProperties.getAppId());
        payConfig.setMchId(weixinPayProperties.getMchId());
        payConfig.setMchKey(weixinPayProperties.getMchKey());
        payConfig.setNotifyUrl(weixinPayProperties.getPayNotifyUrl());
        payConfig.setKeyPath(weixinPayProperties.getKeyPath());
        payConfig.setTradeType("JSAPI");
        payConfig.setSignType("MD5");

        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(false);

        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }

}
